package com.appkubes.mall.restful.application.goods.sku.service.impl;

import com.appkubes.mall.core.entity.MallSpecificAttribute;
import com.appkubes.mall.core.service.impl.BaseMallSpecificAttributeServiceImpl;
import com.appkubes.mall.restful.application.goods.sku.dao.SpecificAttributeDao;
import com.appkubes.mall.restful.application.goods.sku.model.AttributeModel;
import com.appkubes.mall.restful.application.goods.sku.service.SpecificAttributeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpecificAttributeServiceImpl extends BaseMallSpecificAttributeServiceImpl implements SpecificAttributeService {
    @Autowired
    SpecificAttributeDao specificAttributeDao;

    public List<AttributeModel> getList(String appKey, String typeKey) {
        return specificAttributeDao.getList(appKey, typeKey);
    }

    public MallSpecificAttribute getFirstAttr(String typeKey) {
        QueryWrapper<MallSpecificAttribute> queryWrapper = new QueryWrapper();

        MallSpecificAttribute entity = new MallSpecificAttribute();
        entity.setSpecificTypeKey(typeKey);
        queryWrapper.setEntity(entity);

        queryWrapper.orderByDesc("specific_attribute_index");

        List<MallSpecificAttribute> specificAttributeList = this.getBaseMapper().selectList(queryWrapper);
        if (specificAttributeList.size() == 0) return null;
        return specificAttributeList.get(0);
    }
}
